package com.bjpowernode.crm.workbench.service.impl;

import com.bjpowernode.crm.settings.service.UserService;
import com.bjpowernode.crm.workbench.domain.ClueRemark;
import com.bjpowernode.crm.workbench.mapper.ClueRemarkMapper;
import com.bjpowernode.crm.workbench.service.ClueRemarkService;
import lombok.Getter;
import lombok.Setter;

import java.util.Collections;
import java.util.List;

@Getter
@Setter
public class ClueRemarkServiceImpl implements ClueRemarkService {

    /**
     * 访问线索备注数据
     */
    private ClueRemarkMapper clueRemarkMapper;

    /**
     * 处理用户相关业务
     */
    private UserService userService;

    @Override
    public List<ClueRemark> queryClueRemarkByClueId(String clueId) {
        List<ClueRemark> clueRemarks = this.clueRemarkMapper.selectClueRemarkByClueId(clueId);

        //数据库中存放的是创建者和最后编辑者的 id ，结果中需要的是他们的名称
        for (ClueRemark clueRemark : clueRemarks) {
            clueRemark.setCreateBy(this.userService.queryNameById(clueRemark.getCreateBy()));
            clueRemark.setEditBy(this.userService.queryNameById(clueRemark.getEditBy()));
        }

        return clueRemarks;
    }

    @Override
    public void removeClueRemarkByClueId(String clueId) {
        this.clueRemarkMapper.deleteClueRemarkByClueId(clueId);
    }

}
